import { distributionDeliverymanAPI, fetchUpOrDispatchAPI } from '@/api/dispatch/pickUpAPI'

const actions = {

  /*
  * 获取取件作业的action
  *  */
  async fetchPickUpAction(context, pageParams) {
    const { data } = await fetchUpOrDispatchAPI(pageParams)
    context.commit('setPickUpMutation', data)
  },
  /*
  * 分配快递员的action
  *  */
  async distributionDeliverymanAction(context, { courierId, ids }) {
    await distributionDeliverymanAPI({courierId, ids})
    return '快递员分配成功'
  }
}

const mutations = {
  /*
  * 设置取件作业的mutation
  *  */
  setPickUpMutation(state, { counts, items }) {
    state.pickUpList = items
    state.counts = Number(counts)
  }
}
const state = () => {
  return {
    counts: 0,
    pickUpList: []
  }
}

export default {
  actions,
  mutations,
  state,
  namespaced: true
}
